package com.ck.component;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class AsyncThreadComponent {

    @Resource
    ApplicationContext applicationContext;

    public void executeAsyncThread() {
        log.warn("executeAsyncThread:{}", Thread.currentThread().getName());
        AsyncThreadComponent bean = applicationContext.getBean(AsyncThreadComponent.class);
        bean.executeAsyncThreadWithName();
    }

    @Async
    public void executeAsyncThreadWithName() {
        log.warn("executeAsyncThreadWithName:{}", Thread.currentThread().getName());
    }
}
